﻿using System;
using System.Data;
using System.Linq;
using System.Windows;
using WPFExcelReport.Chart;
using System.Windows.Controls;
using WPFExcelReport.Helpers;
using System.ComponentModel;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TVKPYARN : UIVKPOS
    {
        public TVKPYARN()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVKPOS();
            this.DataContext = MV;
            InitializeComponent();
            MESSAGES += "WDCHG;";
        }

        public override void PRODREQ()
        {
            base.PRODREQ();
            switch (app.company)
            {
                case "YGR":

                    break;
            }
            switch (ARTST)
            {
                case "G":
                    TMV.CHKGD(dwVKP, dwVF);
                    break;
            }

        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }

        public override void VKKLOAD(DataRow _dwVKK)
        {
            if (KRS.Length < 1)
                return;
             SResult = TMV.VVVKP(KRS, LFD, LIEFSCH);
             MergeData(SResult, false); 
             if (IsAuto)
             {
                 if (TBMain.Rows.Count == 0)
                     NewCommand(null, null);
             } 
        } 
        
    }
    public partial class VVKPOS
    {

        public void NEWGD(DataRow _dwVKP, DataRow _dwVF)
        {
            if (!IsEdit)
                return;
            if (_dwVKP == null)
                return;
            if (_dwVF == null)
                return;
            double qty = System.Convert.ToDouble(_dwVKP["VKPMENGE1"].ToString()) * 0.01; 
            PM["RUNID"] = this.RUNID;
            PM["AUFTYP"] = "K";
            PM["ART"] = _dwVF["VAFPART"];
            PM["VAR"] = _dwVF["VAFPVAR"];
            PM["FARBE"] = _dwVF["VAFFFARBE"];
            PM["ORDERNUM"] = _dwVKP["VKPAUFKRS"].ToString() + _dwVKP["VKPAUFLFD"].ToString() + _dwVKP["VKPAUFPOS"].ToString()+"VK ";
            PM["DELDATE"] = _dwVKP["VKPLIEFTERM"];
            PM["ALLOCATED"] = _dwVKP["VKPZUGET"];
            PM["QTY"] = qty.ToString();
            PM["ARTSTAGE"] = "S";
            PM["VKPZUSATZ"] = _dwVKP["VKPZUSATZ"];
            PM["VKPAUF"] = _dwVKP["VKPAUFKRS"].ToString() + _dwVKP["VKPAUFLFD"].ToString() + _dwVKP["VKPAUFPOS"].ToString() + "VK ";
            PM["LO"] = _dwVKP["VKPVERSLO"].ToString();
            VGAAUF.Instance.NEWGD610(PM);
        }

        public void CHKGD(DataRow _dwVKP, DataRow _dwVF)
        {
            if (_dwVKP == null)
                return;
            if (_dwVF == null)
                return;
            if (IsEdit)
            {
                //NEWGD(_dwVKP, _dwVF);
            }
            MessageInfo msg = new MessageInfo();
            msg.MSGTYPE = "CHKGD";
            msg.Sender = this.RUNID;
            msg.ACTION = "CHKGD";
            msg.AUFTYP = "K";
            msg.ORDER = _dwVKP["VKPAUFKRS"].ToString() + _dwVKP["VKPAUFLFD"].ToString() + _dwVKP["VKPAUFPOS"].ToString() + "VK ";
            msg.ART = _dwVF["VAFPART"].ToString();
            msg.VAR = _dwVF["VAFPVAR"].ToString();
            msg.FARBE = _dwVF["VAFFFARBE"].ToString();
            msg.QTY = (System.Convert.ToDouble(_dwVKP["VKPMENGE1"].ToString()) * 0.01).ToString();
            msg.P1 = _dwVKP["VKPLIEFTERM"].ToString();
            msg.P2 = _dwVKP["VKPZUGET"].ToString();
            msg.P3 = _dwVKP["VKPZUSATZ"].ToString();
            msg.P4 = "610"; 
            msg.Where = app.User;
            VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", null, "", msg);
        }

        public void CHKFB(DataRow _dwVKP, DataRow _dwVF)
        {
            if (_dwVKP == null)
                return;
            dwData = TBMain.NewRow();
            dwData["VKPMANDANT"] = app.Mandant;
            dwData["VKPSA"] = "FB";
            dwData["VKPAUFKRS"] = _dwVKP["VKPAUFKRS"];
            dwData["VKPAUFLFD"] = _dwVKP["VKPAUFLFD"];
            dwData["VKPAUFPOS"] = _dwVKP["VKPAUFPOS"];
            SResult = QueryVKPOS(dwData, 17);
        }
    }
}
